package cn.tedu.egweibo05.base.interceptors;

import cn.tedu.egweibo05.pojo.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        UserVO userVO = (UserVO)request.getSession().getAttribute("user");
        if (userVO == null){
            log.debug("拦截器拦截用户，未登录");
            response.sendRedirect("/login05.html");
            return false;
        }
        log.debug("用户已登陆");
        return true;
    }
}
